
<!DOCTYPE html>
<html lang="zh-CN">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
        <meta name="description" content="">
        <meta name="author" content="">

        <title>后台</title>

        <link href="__PUBLIC__/images/favicon.ico" rel="shortcut icon" />

        <!-- Bootstrap core CSS -->
        <link rel="stylesheet" href="__PUBLIC__/css/bootstrap.min.css" />
        <link rel="stylesheet" href="__PUBLIC__/css/bootstrap-theme.min.css" />
        <link rel="stylesheet" href="__PUBLIC__/css/dashboard.css" />
        <link rel="stylesheet" href="__PUBLIC__/css/icheck/all.css" />
    </head>

    <body>

    <include file="Common/topNav" />

    <div class="container-fluid">
        <div class="row">
            <include file="Common/leftMenu" />
            <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
                <div class="cont-title clearfix">
                    <div class="title">楼宇列表</div>
                    <div class="btn-group">
                    	<button class="btn" type="button" id="add_house">添加</button>
                        <button class="btn" type="button" id="del_house">删除</button>
                    </div>
                </div>
                <include file="search" />
                <div class="table-responsive">
                    <table class="table table-striped table-hover" id="tableData">
                        <thead>
                            <tr>
                            	<th>
                            		<input type="checkbox" id="checkAll" />
                            	</th>
                            	<th>序号</th>
                                <th>楼宇名称</th>
                                <th>所属街道</th>
                                <th>楼宇地址</th>
                                <th>总面积（m&sup2;）</th>
                                <th>空置面积（m&sup2;）</th>
                                <th>是否有效</th>
                                <th>创建时间</th>
                                <th>操作员</th>
                                <th>操作</th>
                            </tr>
                        </thead>
                        <tbody>
                        <empty name="houseList">
                        	<tr>
                        		<td colspan="10">没有相关记录</td>
                        	</tr>
                        </empty>
                        <foreach name="houseList" item="house">
                            <tr>
                            	<td>
                            		<input type="checkbox" name="house_check[]" value="{$house.id}" <if condition="$house.status eq 0">disabled</if> />
                            	</td>
                            	<td>{$key|getLineNum=$nowPage,$pageSize}</td>
                                <td class="pull-left">
                                    {$house.name}
                                    <if condition="$features[$house['id']]">
                                        <span class="label label-primary" style="margin-left:5px;">{$features[$house['id']]}</span>
                                    </if>
                                </td>
                                <td>{$house.orgname}</td>
                                <td>{$house.position}</td>
                                <td>{$house.area_use|number_format=2}</td>
                                <td>{$house.area_remain|number_format=2}</td>
                                <td>
                                	<if condition="$house.status eq 1">
                                        <span class="label label-success">是</span>
                                	<else/>
                                        <span class="label label-danger">否</span>
                                	</if>
                                </td>
                                <td>{$house.create_time|date="Y-m-d H:i",###}</td>
                                <td>{$house.operator}</td>
                            <td>
                                <a thisId="{$house.id}" href="javascript:void(0);" class="house_detail">查看详情</a>
                                	 | <a thisId="{$house.id}" href="javascript:void(0);" class="house_edit">修改</a>
                                     | <a thisId="{$house.id}" href="javascript:void(0);" class="house_del">删除</a>
                                     | <a thisId="{$house.id}" href="javascript:void(0);" class="house_manager">操作员设置</a>
                            </td>
                            </tr>
                        </foreach>    
                        </tbody>
                    </table>
                    <div class="page">
                    	{$page}
                    </div>
                </div>
            </div>
        </div>
    </div>
    

    <include file="Common/modalHtmls" />
    <script type="text/javascript" src="__PUBLIC__/js/jquery.min.js"></script>
    <script type="text/javascript" src="__PUBLIC__/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="__PUBLIC__/js/common.js"></script>
    <script type="text/javascript" src="__PUBLIC__/js/icheck.min.js"></script>
    <script type="text/javascript" src="http://api.map.baidu.com/getscript?v=2.0&ak=Q1oD5ADWcba2LGaq9Y067YrplSKgzFYj"></script>
    <script type="text/javascript">
    	$(function(){
    		$("input[type='checkbox']").iCheck({
    	        checkboxClass: 'icheckbox_flat-blue',
    	        radioClass: 'iradio_flat-blue',
    	        increaseArea: '10%'
    	    });
    		$("#add_house").bind("click",addHouse);
    		$("#del_house").bind("click",delHouseBatch);
    		$("#tableData .house_detail").click(function(){
    			showDetail(this);
    		});
    		$("#tableData .house_edit").click(function(){
    			editHouse(this);
    		});
    		$("#tableData .house_del").click(function(){
    			delHouse(this);
    		});
    		$("#tableData .house_recover").click(function(){
    			recoverHouse(this);
    		});
    		$("#tableData .house_manager").click(function(){
    			setManager(this);
    		});
    		chooseAll();
    	});
    	
    	function chooseAll(){
    		$('#checkAll').on('ifChecked', function(event){
    			$("input[name='house_check[]']:checkbox").each(function(){
    				var $this = $(this);
        			if(!$this.prop("disabled")){
        				$this.iCheck("check");
        			}
        		});
    		});
    		$('#checkAll').on('ifUnchecked', function(event){
    			$("input[name='house_check[]']:checkbox").iCheck("uncheck");
    		});
    	}
    	
    	function addHouse(){
    		common.loading('正在加载...');
    		common.htmlAjax("{:U('Admin/House/add')}", {}, function (html) {
    			common.closeLoading();
                $("#commonModal").html(html).modal({show: true, backdrop: 'static', keyboard: false});
            });
    	}
    	
    	function delHouseBatch(){
    		var str = "";
    		$("input[name='house_check[]']:checkbox").each(function(){
    			if(true == $(this).is(':checked')){
    				str += "," + $(this).val();
    			}
    		});
    		if(str == ""){
    			common.alert("提示","请至少选择一条记录");
    			return;
    		}
    		common.confirm("提示","确认删除选中的楼宇吗？",function(){
	    		str = str.substring(1);
	    		var param = {id:str};
	    		$.ajax({
	                url: "{:U('Admin/House/delete')}",
	                type: "post",
	                dataType: "json",
	                data: param,
	                success: function (data) {
	                    if(data.status){
	                    	common.alert("提示","楼宇已成功删除!",function(){
	                            common.reload();
	                        });
	                    }
	                }
	            });
    		});
    	}
    	
    	function showDetail(obj){
    		var id = $(obj).attr("thisId");
    		common.loading('正在加载...');
    		common.htmlAjax("{:U('Admin/House/detail')}", {id:id}, function (html) {
    			common.closeLoading();
                $("#commonModal").html(html).modal('toggle');
            });
    	}
    	
    	function editHouse(obj){
    		var id = $(obj).attr("thisId");
    		common.loading('正在加载...');
    		common.htmlAjax("{:U('Admin/House/add')}", {id:id}, function (html) {
    			common.closeLoading();
                $("#commonModal").html(html).modal({show: true, backdrop: 'static', keyboard: false});
            });
    	}
    	
    	function delHouse(obj){
    		common.confirm("提示","确认删除该楼宇吗？",function(){
	    		var id = $(obj).attr("thisId");
	    		var param = {id:id};
	    		$.ajax({
	                url: "{:U('Admin/House/delete')}",
	                type: "post",
	                dataType: "json",
	                data: param,
	                success: function (data) {
	                    if(data.status){
	                    	common.alert("提示","楼宇已成功删除!",function(){
	                            common.reload();
	                        });
	                    }
	                }
	            });
    		});
    	}
    	
    	function recoverHouse(obj){
    		common.confirm("提示","确认恢复该楼宇吗？",function(){
	    		var id = $(obj).attr("thisId");
	    		var param = {id:id};
	    		$.ajax({
	                url: "{:U('Admin/House/recover')}",
	                type: "post",
	                dataType: "json",
	                data: param,
	                success: function (data) {
	                    if(data.status){
	                    	common.alert("提示","楼宇已成功恢复!",function(){
	                            common.reload();
	                        });
	                    }
	                }
	            });
    		});
    	}
    	
    	function setManager(obj){
    		var id = $(obj).attr("thisId");
    		common.htmlAjax("{:U('Admin/House/setManager')}", {id:id}, function (html) {
                $("#commonModal").html(html).modal('toggle');
            });
    	}
    </script>
</body>
</html>
